package com.imau.brand.controller;

import com.alibaba.fastjson.JSON;
import com.imau.brand.bean.Brand;
import com.imau.brand.service.BrandService;
import com.imau.brand.service.impl.BrandServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/brandSel")
public class BrandSelController extends HttpServlet {

    /**
     * 初始化业务层对象
     */
    private BrandService brandService = new BrandServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1.获取前端发送的数据
        String id = request.getParameter("id");

        //2.调用业务层方法保存
        Brand brand = brandService.findById(Integer.valueOf(id));
        //4.响应结果
        response.getWriter().write(JSON.toJSONString(brand));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
